package com.tinyengine.it.controller.db;

import com.tinyengine.it.common.base.Result;
import com.tinyengine.it.common.utils.JavaDataType;
import com.tinyengine.it.common.utils.ParType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.stream.Collectors;

@Tag(name = "数据类型")
@RestController
@RequestMapping("/data/type/api")
@Validated
public class DbDataTypeController {

    @Parameter(name = "parType", description = "按类型", in = ParameterIn.QUERY)
    @Operation(summary = "获取所有数据类型")
    @PostMapping("/getAllDataType")
    public Result addAndUpdate(ParType parType) {

        switch (parType) {
            case HEADER:
                return Result.success(Arrays.asList(
                        JavaDataType.String.getValue(),
                        JavaDataType.Boolean.getValue(),
                        JavaDataType.DateTime.getValue()
                ));
            default:
                return Result.success(Arrays.stream(JavaDataType.values()).map(m -> m.getValue()).collect(Collectors.toList()));
        }
    }
}
